package com.wetao.lib_common.greendao.dao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.wetao.lib_common.greendao.model.PagePictureOnline;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "PAGE_PICTURE_ONLINE".
*/
public class PagePictureOnlineDao extends AbstractDao<PagePictureOnline, Long> {

    public static final String TABLENAME = "PAGE_PICTURE_ONLINE";

    /**
     * Properties of entity PagePictureOnline.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property QuestionId = new Property(1, Integer.class, "questionId", false, "QUESTION_ID");
        public final static Property QuestionNo = new Property(2, Integer.class, "questionNo", false, "QUESTION_NO");
        public final static Property PictureUrl = new Property(3, String.class, "pictureUrl", false, "PICTURE_URL");
        public final static Property LocalClipPath = new Property(4, String.class, "localClipPath", false, "LOCAL_CLIP_PATH");
        public final static Property LocalPath = new Property(5, String.class, "localPath", false, "LOCAL_PATH");
        public final static Property AnswerIndex = new Property(6, Integer.class, "answerIndex", false, "ANSWER_INDEX");
        public final static Property Min_h = new Property(7, Float.class, "Min_h", false, "MIN_H");
        public final static Property Max_h = new Property(8, Float.class, "Max_h", false, "MAX_H");
        public final static Property PictureId = new Property(9, String.class, "pictureId", false, "PICTURE_ID");
        public final static Property BookId = new Property(10, Integer.class, "bookId", false, "BOOK_ID");
        public final static Property PageNumber = new Property(11, Integer.class, "pageNumber", false, "PAGE_NUMBER");
        public final static Property SectionNo = new Property(12, Integer.class, "sectionNo", false, "SECTION_NO");
        public final static Property OwnerNo = new Property(13, Integer.class, "ownerNo", false, "OWNER_NO");
        public final static Property PageSerial = new Property(14, String.class, "pageSerial", false, "PAGE_SERIAL");
        public final static Property AssistantExamId = new Property(15, Long.class, "assistantExamId", false, "ASSISTANT_EXAM_ID");
    }

    private Query<PagePictureOnline> assistantExamOnline_PagePictureListQuery;

    public PagePictureOnlineDao(DaoConfig config) {
        super(config);
    }
    
    public PagePictureOnlineDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"PAGE_PICTURE_ONLINE\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"QUESTION_ID\" INTEGER NOT NULL ," + // 1: questionId
                "\"QUESTION_NO\" INTEGER," + // 2: questionNo
                "\"PICTURE_URL\" TEXT," + // 3: pictureUrl
                "\"LOCAL_CLIP_PATH\" TEXT," + // 4: localClipPath
                "\"LOCAL_PATH\" TEXT," + // 5: localPath
                "\"ANSWER_INDEX\" INTEGER," + // 6: answerIndex
                "\"MIN_H\" REAL," + // 7: Min_h
                "\"MAX_H\" REAL," + // 8: Max_h
                "\"PICTURE_ID\" TEXT NOT NULL UNIQUE ," + // 9: pictureId
                "\"BOOK_ID\" INTEGER," + // 10: bookId
                "\"PAGE_NUMBER\" INTEGER," + // 11: pageNumber
                "\"SECTION_NO\" INTEGER," + // 12: sectionNo
                "\"OWNER_NO\" INTEGER," + // 13: ownerNo
                "\"PAGE_SERIAL\" TEXT," + // 14: pageSerial
                "\"ASSISTANT_EXAM_ID\" INTEGER NOT NULL );"); // 15: assistantExamId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"PAGE_PICTURE_ONLINE\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, PagePictureOnline entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getQuestionId());
 
        Integer questionNo = entity.getQuestionNo();
        if (questionNo != null) {
            stmt.bindLong(3, questionNo);
        }
 
        String pictureUrl = entity.getPictureUrl();
        if (pictureUrl != null) {
            stmt.bindString(4, pictureUrl);
        }
 
        String localClipPath = entity.getLocalClipPath();
        if (localClipPath != null) {
            stmt.bindString(5, localClipPath);
        }
 
        String localPath = entity.getLocalPath();
        if (localPath != null) {
            stmt.bindString(6, localPath);
        }
 
        Integer answerIndex = entity.getAnswerIndex();
        if (answerIndex != null) {
            stmt.bindLong(7, answerIndex);
        }
 
        Float Min_h = entity.getMin_h();
        if (Min_h != null) {
            stmt.bindDouble(8, Min_h);
        }
 
        Float Max_h = entity.getMax_h();
        if (Max_h != null) {
            stmt.bindDouble(9, Max_h);
        }
        stmt.bindString(10, entity.getPictureId());
 
        Integer bookId = entity.getBookId();
        if (bookId != null) {
            stmt.bindLong(11, bookId);
        }
 
        Integer pageNumber = entity.getPageNumber();
        if (pageNumber != null) {
            stmt.bindLong(12, pageNumber);
        }
 
        Integer sectionNo = entity.getSectionNo();
        if (sectionNo != null) {
            stmt.bindLong(13, sectionNo);
        }
 
        Integer ownerNo = entity.getOwnerNo();
        if (ownerNo != null) {
            stmt.bindLong(14, ownerNo);
        }
 
        String pageSerial = entity.getPageSerial();
        if (pageSerial != null) {
            stmt.bindString(15, pageSerial);
        }
        stmt.bindLong(16, entity.getAssistantExamId());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, PagePictureOnline entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getQuestionId());
 
        Integer questionNo = entity.getQuestionNo();
        if (questionNo != null) {
            stmt.bindLong(3, questionNo);
        }
 
        String pictureUrl = entity.getPictureUrl();
        if (pictureUrl != null) {
            stmt.bindString(4, pictureUrl);
        }
 
        String localClipPath = entity.getLocalClipPath();
        if (localClipPath != null) {
            stmt.bindString(5, localClipPath);
        }
 
        String localPath = entity.getLocalPath();
        if (localPath != null) {
            stmt.bindString(6, localPath);
        }
 
        Integer answerIndex = entity.getAnswerIndex();
        if (answerIndex != null) {
            stmt.bindLong(7, answerIndex);
        }
 
        Float Min_h = entity.getMin_h();
        if (Min_h != null) {
            stmt.bindDouble(8, Min_h);
        }
 
        Float Max_h = entity.getMax_h();
        if (Max_h != null) {
            stmt.bindDouble(9, Max_h);
        }
        stmt.bindString(10, entity.getPictureId());
 
        Integer bookId = entity.getBookId();
        if (bookId != null) {
            stmt.bindLong(11, bookId);
        }
 
        Integer pageNumber = entity.getPageNumber();
        if (pageNumber != null) {
            stmt.bindLong(12, pageNumber);
        }
 
        Integer sectionNo = entity.getSectionNo();
        if (sectionNo != null) {
            stmt.bindLong(13, sectionNo);
        }
 
        Integer ownerNo = entity.getOwnerNo();
        if (ownerNo != null) {
            stmt.bindLong(14, ownerNo);
        }
 
        String pageSerial = entity.getPageSerial();
        if (pageSerial != null) {
            stmt.bindString(15, pageSerial);
        }
        stmt.bindLong(16, entity.getAssistantExamId());
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public PagePictureOnline readEntity(Cursor cursor, int offset) {
        PagePictureOnline entity = new PagePictureOnline( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.getInt(offset + 1), // questionId
            cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // questionNo
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // pictureUrl
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // localClipPath
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // localPath
            cursor.isNull(offset + 6) ? null : cursor.getInt(offset + 6), // answerIndex
            cursor.isNull(offset + 7) ? null : cursor.getFloat(offset + 7), // Min_h
            cursor.isNull(offset + 8) ? null : cursor.getFloat(offset + 8), // Max_h
            cursor.getString(offset + 9), // pictureId
            cursor.isNull(offset + 10) ? null : cursor.getInt(offset + 10), // bookId
            cursor.isNull(offset + 11) ? null : cursor.getInt(offset + 11), // pageNumber
            cursor.isNull(offset + 12) ? null : cursor.getInt(offset + 12), // sectionNo
            cursor.isNull(offset + 13) ? null : cursor.getInt(offset + 13), // ownerNo
            cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // pageSerial
            cursor.getLong(offset + 15) // assistantExamId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, PagePictureOnline entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setQuestionId(cursor.getInt(offset + 1));
        entity.setQuestionNo(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
        entity.setPictureUrl(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setLocalClipPath(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setLocalPath(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setAnswerIndex(cursor.isNull(offset + 6) ? null : cursor.getInt(offset + 6));
        entity.setMin_h(cursor.isNull(offset + 7) ? null : cursor.getFloat(offset + 7));
        entity.setMax_h(cursor.isNull(offset + 8) ? null : cursor.getFloat(offset + 8));
        entity.setPictureId(cursor.getString(offset + 9));
        entity.setBookId(cursor.isNull(offset + 10) ? null : cursor.getInt(offset + 10));
        entity.setPageNumber(cursor.isNull(offset + 11) ? null : cursor.getInt(offset + 11));
        entity.setSectionNo(cursor.isNull(offset + 12) ? null : cursor.getInt(offset + 12));
        entity.setOwnerNo(cursor.isNull(offset + 13) ? null : cursor.getInt(offset + 13));
        entity.setPageSerial(cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14));
        entity.setAssistantExamId(cursor.getLong(offset + 15));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(PagePictureOnline entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(PagePictureOnline entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(PagePictureOnline entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "pagePictureList" to-many relationship of AssistantExamOnline. */
    public List<PagePictureOnline> _queryAssistantExamOnline_PagePictureList(Long assistantExamId) {
        synchronized (this) {
            if (assistantExamOnline_PagePictureListQuery == null) {
                QueryBuilder<PagePictureOnline> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.AssistantExamId.eq(null));
                assistantExamOnline_PagePictureListQuery = queryBuilder.build();
            }
        }
        Query<PagePictureOnline> query = assistantExamOnline_PagePictureListQuery.forCurrentThread();
        query.setParameter(0, assistantExamId);
        return query.list();
    }

}
